package com.grass.appointment.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.grass.appointment.C2694R;
import java.util.Objects;

public class RewardDialog extends DialogFragment implements View.OnClickListener {
    private EditText edit_detail;
    private EditText edit_gold;
    private RewardInterface rewardInterface;

    public interface RewardInterface {
        void onClickReward(int i, String str);
    }

    public static RewardDialog newInstance() {
        Bundle bundle = new Bundle();
        RewardDialog rewardDialog = new RewardDialog();
        rewardDialog.setArguments(bundle);
        return rewardDialog;
    }

    public void setRewardInterface(RewardInterface rewardInterface2) {
        this.rewardInterface = rewardInterface2;
    }

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return layoutInflater.inflate(C2694R.C2699layout.dialog_reward, viewGroup, false);
    }

    @Override // androidx.fragment.app.DialogFragment
    public Dialog onCreateDialog(Bundle bundle) {
        DialogC27941 r3 = new Dialog((Context) Objects.requireNonNull(getActivity()), C2694R.C2701style.MyDialogStyle) {
            /* class com.grass.appointment.dialog.RewardDialog.DialogC27941 */

            public void onBackPressed() {
                dismiss();
            }
        };
        r3.setCancelable(true);
        r3.setCanceledOnTouchOutside(true);
        return r3;
    }

    @Override // androidx.fragment.app.Fragment
    public void onViewCreated(View view, Bundle bundle) {
        EditText editText = (EditText) view.findViewById(C2694R.C2697id.edit_gold);
        this.edit_gold = editText;
        editText.addTextChangedListener(new TextWatcher() {
            /* class com.grass.appointment.dialog.RewardDialog.C27952 */

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void afterTextChanged(Editable editable) {
                String obj = editable.toString();
                if (editable.toString().length() > 1 && obj.startsWith("0")) {
                    editable.replace(0, 1, "");
                }
            }
        });
        this.edit_detail = (EditText) view.findViewById(C2694R.C2697id.edit_detail);
        view.findViewById(C2694R.C2697id.btn_reward).setOnClickListener(this);
        view.findViewById(C2694R.C2697id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            /* class com.grass.appointment.dialog.RewardDialog.View$OnClickListenerC27963 */

            public void onClick(View view) {
                RewardDialog.this.dismiss();
            }
        });
        super.onViewCreated(view, bundle);
    }

    @Override // androidx.fragment.app.Fragment, androidx.fragment.app.DialogFragment
    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
    }

    public void onClick(View view) {
        if (view.getId() == C2694R.C2697id.btn_reward) {
            String rewardMoney = getRewardMoney();
            String rewardContent = getRewardContent();
            if (TextUtils.isEmpty(rewardMoney)) {
                ToastUtils.getInstance().showSigh("請輸入打賞金額");
                return;
            }
            try {
                int parseInt = Integer.parseInt(rewardMoney);
                if (parseInt < 1) {
                    ToastUtils.getInstance().showSigh("最低不能少於 1 金幣");
                    return;
                }
                dismiss();
                if (this.rewardInterface != null) {
                    this.rewardInterface.onClickReward(parseInt, rewardContent);
                }
            } catch (Exception unused) {
                ToastUtils.getInstance().showSigh("輸入金額錯誤");
            }
        }
    }

    private String getRewardMoney() {
        return this.edit_gold.getText().toString().trim();
    }

    private String getRewardContent() {
        return this.edit_detail.getText().toString().trim();
    }

    @Override // androidx.fragment.app.DialogFragment
    public void show(FragmentManager fragmentManager, String str) {
        FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
        beginTransaction.add(this, str);
        beginTransaction.commitAllowingStateLoss();
    }

    @Override // androidx.fragment.app.DialogFragment
    public void dismiss() {
        super.dismissAllowingStateLoss();
    }
}
